<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Compile Values</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Compile Values' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../inform7n.html">Inform7</a></li><li><a href="index.html">imperative</a></li><li><a href="index.html#2">Chapter 2: Values</a></li><li><b>Compile Values</b></li></ul></div>
<p class="purpose">To compile specifications of values into Inter value opcodes or array entries.</p>

<ul class="toc"><li><a href="2-cv.html#SP1">&#167;1. Introduction</a></li><li><a href="2-cv.html#SP2">&#167;2. An API for compiling values</a></li><li><a href="2-cv.html#SP6">&#167;6. Implementation</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Introduction.</b>Quite a range of data can be held as specifications: see <a href="../values-module/2-spc.html" class="internal">Specifications (in values)</a>.
Inside the compiler these are stored as <span class="extract"><span class="extract-syntax">parse_node</span></span> pointers. This section of
code aims to provide a single unified way to compile values, even though:
</p>

<ul class="items"><li>&#9679; We may need to compile either an array entry or an Inter <span class="extract"><span class="extract-syntax">val</span></span> opcode.
We abstract this using <a href="../building-module/3-vh.html" class="internal">Value Holsters (in building)</a>, holders into which
compiled values are placed.
</li><li>&#9679; We sometimes need to compile a value which needs to be converted to a
different kind first, a process called "casting".
</li><li>&#9679; Sometimes a fresh copy of a value is needed, and sometimes a reference to
its existing copy.
</li></ul>
<p class="commentary">This complexity was historically managed by having persistent "compilation
modes" which Inform would enter for short periods and then exit, and during
which specifications would compile difficulty. This had worked well enough
since 2005 but by the 2020s there were 12 different modes, making in principle
1024 different combinations to worry over. Because modes were entered and
exited far away from their consequences, and in dozens of different parts of
the compiler, it became difficult to reason with any confidence about what
would happen, so worrying was about all that could be done.
</p>

<p class="commentary">In April 2021, all modes were removed except <span class="extract"><span class="extract-syntax">compile_spec_in_constant_mode</span></span>,
and even that one is relatively benign: entry and exit into it is managed
automatically by the code below, so that the rest of Inform no longer needs
to think about compilation modes at all.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">compile_spec_in_constant_mode</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::compiling_in_constant_mode</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">CompileValues::compiling_in_constant_mode</span></span>:<br/>Compile Rvalues - <a href="2-cr.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">void</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">compile_spec_in_constant_mode</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. An API for compiling values.</b>When the rest of Inform wants to compile a value, it should call one of the
following functions.
</p>

<p class="commentary">To begin with, compiling to array entries:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_array_entry_of_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP2" class="function-link"><span class="function-syntax">CompileValues::to_array_entry</span></a><span class="plain-syntax">(</span>
<span class="plain-syntax">        </span><a href="2-cv.html#SP7" class="function-link"><span class="function-syntax">CompileValues::cast_constant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">));</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_array_entry</span><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">value_holster</span><span class="plain-syntax"> </span><span class="identifier-syntax">VH</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Holsters::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_DATA_VHMODE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP6" class="function-link"><span class="function-syntax">CompileValues::to_holster</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="constant-syntax">COMPILE_SPEC_AS_CONSTANT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_pair</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Holsters::unholster_to_pair</span><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">VH</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">EmitArrays::generic_entry</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>Now constants, which can be compiled either to a holster or to a pair of <span class="extract"><span class="extract-syntax">inter_t</span></span>
numbers. Use the latter as little as possible.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::constant_to_holster</span><span class="plain-syntax">(</span><span class="identifier-syntax">value_holster</span><span class="plain-syntax"> *</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP6" class="function-link"><span class="function-syntax">CompileValues::to_holster</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">VH</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><a href="2-cv.html#SP7" class="function-link"><span class="function-syntax">CompileValues::cast_constant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">), </span><span class="constant-syntax">COMPILE_SPEC_AS_CONSTANT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="identifier-syntax">inter_pair</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::constant_to_pair</span><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">value_holster</span><span class="plain-syntax"> </span><span class="identifier-syntax">VH</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Holsters::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_DATA_VHMODE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP3" class="function-link"><span class="function-syntax">CompileValues::constant_to_holster</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Holsters::unholster_to_pair</span><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">VH</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>A general method (i.e., not restricted to constant context) for compiling to a
pair value. Use this as little as possible.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">inter_pair</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_pair</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">CompileValues::to_pair</span></span>:<br/>Compile Invocations Inline - <a href="5-cii.html#SP14">&#167;14</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">spec</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">value_holster</span><span class="plain-syntax"> </span><span class="identifier-syntax">VH</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Holsters::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_DATA_VHMODE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP6" class="function-link"><span class="function-syntax">CompileValues::to_holster</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">spec</span><span class="plain-syntax">, </span><span class="constant-syntax">COMPILE_SPEC_AS_VALUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Holsters::unholster_to_pair</span><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">VH</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Finally, for compiling to Inter opcodes in a <span class="extract"><span class="extract-syntax">val</span></span> context &mdash; in other words,
for values as they appear in imperative code rather than in data structures.
A "fresh" value should be made when we want the value compiled to be a new,
independent copy of the data in question. Consider:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">let</span><span class="plain-syntax"> </span><span class="identifier-syntax">T</span><span class="plain-syntax"> </span><span class="identifier-syntax">be</span><span class="plain-syntax"> { </span><span class="constant-syntax">2</span><span class="plain-syntax">, </span><span class="constant-syntax">3</span><span class="plain-syntax">, </span><span class="constant-syntax">5</span><span class="plain-syntax">, </span><span class="constant-syntax">7</span><span class="plain-syntax"> };</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">let</span><span class="plain-syntax"> </span><span class="identifier-syntax">U</span><span class="plain-syntax"> </span><span class="identifier-syntax">be</span><span class="plain-syntax"> </span><span class="identifier-syntax">T</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">add</span><span class="plain-syntax"> </span><span class="constant-syntax">11</span><span class="plain-syntax"> </span><span class="identifier-syntax">to</span><span class="plain-syntax"> </span><span class="identifier-syntax">T</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary">Clearly <span class="extract"><span class="extract-syntax">U</span></span> must be set to a fresh copy of the data in <span class="extract"><span class="extract-syntax">T</span></span>, not a reference to the
same data. So the <span class="extract"><span class="extract-syntax">T</span></span> in line 2 must be compiled as "fresh", whereas the <span class="extract"><span class="extract-syntax">T</span></span> in
line 3 must not.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_code_val</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">CompileValues::to_code_val</span></span>:<br/>Compile Rvalues - <a href="2-cr.html#SP1_3">&#167;1.3</a><br/>Compile Lvalues - <a href="2-cl.html#SP1_3">&#167;1.3</a>, <a href="2-cl.html#SP1_3_2">&#167;1.3.2</a>, <a href="2-cl.html#SP1_4">&#167;1.4</a>, <a href="2-cl.html#SP2">&#167;2</a><br/>Compile Conditions - <a href="2-cc.html#SP1">&#167;1</a>, <a href="2-cc.html#SP1_1">&#167;1.1</a>, <a href="2-cc.html#SP1_2">&#167;1.2</a><br/>Matching Action Patterns - <a href="2-map.html#SP3_3_1_1_1_25">&#167;3.3.1.1.1.25</a>, <a href="2-map.html#SP7">&#167;7</a>, <a href="2-map.html#SP7_2_1">&#167;7.2.1</a>, <a href="2-map.html#SP7_2_2">&#167;7.2.2</a>, <a href="2-map.html#SP7_2_3">&#167;7.2.3</a><br/>Compile Loops - <a href="4-cl.html#SP1_2">&#167;1.2</a>, <a href="4-cl.html#SP2">&#167;2</a>, <a href="4-cl.html#SP4">&#167;4</a><br/>Deciding to Defer - <a href="4-dtd.html#SP4_2">&#167;4.2</a>, <a href="4-dtd.html#SP15">&#167;15</a>, <a href="4-dtd.html#SP17">&#167;17</a>, <a href="4-dtd.html#SP18">&#167;18</a>, <a href="4-dtd.html#SP20">&#167;20</a>, <a href="4-dtd.html#SP21">&#167;21</a>, <a href="4-dtd.html#SP22">&#167;22</a><br/>Cinders and Deferrals - <a href="4-cad.html#SP4">&#167;4</a><br/>Compile Invocations As Calls - <a href="5-ciac.html#SP3">&#167;3</a><br/>Compile Invocations Inline - <a href="5-cii.html#SP13">&#167;13</a>, <a href="5-cii.html#SP15">&#167;15</a><br/>Compile Solutions to Equations - <a href="5-cste.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val_inner</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="constant-syntax">COMPILE_SPEC_AS_VALUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_code_val_of_kind</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">CompileValues::to_code_val_of_kind</span></span>:<br/>Compile Rvalues - <a href="2-cr.html#SP6">&#167;6</a><br/>Compile Schemas - <a href="4-cs.html#SP3_2">&#167;3.2</a>, <a href="4-cs.html#SP5_2">&#167;5.2</a><br/>Compile Blocks and Lines - <a href="5-cbal.html#SP4_4_4_2">&#167;4.4.4.2</a>, <a href="5-cbal.html#SP4_4_4_5">&#167;4.4.4.5</a>, <a href="5-cbal.html#SP4_4_4_1_2">&#167;4.4.4.1.2</a><br/>Compile Invocations Inline - <a href="5-cii.html#SP6_1_1_3">&#167;6.1.1.3</a>, <a href="5-cii.html#SP6_1_1_4_10">&#167;6.1.1.4.10</a>, <a href="5-cii.html#SP6_1_1_4_11">&#167;6.1.1.4.11</a>, <a href="5-cii.html#SP6_5_10">&#167;6.5.10</a>, <a href="5-cii.html#SP6_5_10_1">&#167;6.5.10.1</a>, <a href="5-cii.html#SP6_5_10_2">&#167;6.5.10.2</a>, <a href="5-cii.html#SP6_5_10_3">&#167;6.5.10.3</a><br/>Compile Arithmetic - <a href="5-ca.html#SP2">&#167;2</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val_inner</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K</span><span class="plain-syntax">, </span><span class="constant-syntax">COMPILE_SPEC_AS_VALUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_fresh_code_val_of_kind</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">CompileValues::to_fresh_code_val_of_kind</span></span>:<br/>Compile Schemas - <a href="4-cs.html#SP3_2">&#167;3.2</a>, <a href="4-cs.html#SP5_2">&#167;5.2</a><br/>Compile Invocations - <a href="5-ci.html#SP1_3_1_1_1_2">&#167;1.3.1.1.1.2</a><br/>Compile Invocations As Calls - <a href="5-ciac.html#SP2_2">&#167;2.2</a><br/>Compile Invocations Inline - <a href="5-cii.html#SP6_1_1_3">&#167;6.1.1.3</a>, <a href="5-cii.html#SP6_1_1_4_8_1">&#167;6.1.1.4.8.1</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP5" class="function-link"><span class="function-syntax">CompileValues::to_code_val_inner</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K</span><span class="plain-syntax">, </span><span class="constant-syntax">COMPILE_SPEC_AS_FRESH_VALUE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_code_val_inner</span><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">how</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">down</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">K</span><span class="plain-syntax">) </span><span class="identifier-syntax">value</span><span class="plain-syntax"> = </span><a href="2-cv.html#SP8" class="function-link"><span class="function-syntax">CompileValues::cast_nonconstant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">down</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">value_holster</span><span class="plain-syntax"> </span><span class="identifier-syntax">VH</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Holsters::new</span><span class="plain-syntax">(</span><span class="identifier-syntax">INTER_VAL_VHMODE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP6" class="function-link"><span class="function-syntax">CompileValues::to_holster</span></a><span class="plain-syntax">(&amp;</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">how</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">down</span><span class="plain-syntax">) </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Implementation.</b>All of the functions in the above API make use of these private ones:
</p>

<pre class="definitions code-font"><span class="definition-keyword">define</span> <span class="constant-syntax">COMPILE_SPEC_AS_CONSTANT</span><span class="plain-syntax">    </span><span class="constant-syntax">1</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">COMPILE_SPEC_AS_VALUE</span><span class="plain-syntax">       </span><span class="constant-syntax">2</span>
<span class="definition-keyword">define</span> <span class="constant-syntax">COMPILE_SPEC_AS_FRESH_VALUE</span><span class="plain-syntax"> </span><span class="constant-syntax">3</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::to_holster</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">CompileValues::to_holster</span></span>:<br/><a href="2-cv.html#SP2">&#167;2</a>, <a href="2-cv.html#SP3">&#167;3</a>, <a href="2-cv.html#SP4">&#167;4</a>, <a href="2-cv.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">value_holster</span><span class="plain-syntax"> *</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">how</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">how</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMPILE_SPEC_AS_CONSTANT:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">EXPRESSIONS</span><span class="plain-syntax">, </span><span class="string-syntax">"Compiling (const): $P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMPILE_SPEC_AS_VALUE:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">EXPRESSIONS</span><span class="plain-syntax">, </span><span class="string-syntax">"Compiling (value): $P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMPILE_SPEC_AS_FRESH_VALUE:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">LOGIF</span><span class="plain-syntax">(</span><span class="identifier-syntax">EXPRESSIONS</span><span class="plain-syntax">, </span><span class="string-syntax">"Compiling (fresh): $P\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">s</span><span class="plain-syntax"> = </span><span class="identifier-syntax">compile_spec_in_constant_mode</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">how</span><span class="plain-syntax"> == </span><span class="constant-syntax">COMPILE_SPEC_AS_CONSTANT</span><span class="plain-syntax">) </span><span class="identifier-syntax">compile_spec_in_constant_mode</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">compile_spec_in_constant_mode</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG_INDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-cv.html#SP6_1" class="named-paragraph-link"><span class="named-paragraph">Take care of any freshness</span><span class="named-paragraph-number">6.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOG_OUTDENT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">compile_spec_in_constant_mode</span><span class="plain-syntax"> = </span><span class="identifier-syntax">s</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6_1" class="paragraph-anchor"></a><b>&#167;6.1. </b>This implements "fresh" mode. For regular values like numbers there's no
difference, but if our value is a block value such as a list then we evaluate to
a copy of it, not to the original. Making that copy means calling <span class="extract"><span class="extract-syntax">CopyPV</span></span>
at runtime, so it cannot be done in a data holster (i.e., when <span class="extract"><span class="extract-syntax">VH</span></span> is an
<span class="extract"><span class="extract-syntax">INTER_DATA_VHMODE</span></span> holster).
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Take care of any freshness</span><span class="named-paragraph-number">6.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NonlocalVariables::substitute_constants</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_found</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::to_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP9" class="function-link"><span class="function-syntax">CompileValues::note_that_kind_is_used</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K_found</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">made_fresh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">how</span><span class="plain-syntax"> == </span><span class="constant-syntax">COMPILE_SPEC_AS_FRESH_VALUE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">VH</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">vhmode_wanted</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INTER_DATA_VHMODE</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"must compile by reference in INTER_DATA_VHMODE"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::to_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">K</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">Kinds::Behaviour::uses_block_values</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::call</span><span class="plain-syntax">(</span><span class="identifier-syntax">Hierarchy::find</span><span class="plain-syntax">(</span><span class="identifier-syntax">COPYPV_HL</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">EmitCode::down</span><span class="plain-syntax">();</span>
<span class="plain-syntax">                </span><a href="3-sf.html#SP21" class="function-link"><span class="function-syntax">Frames::emit_new_local_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">made_fresh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="2-cv.html#SP6_1_1" class="named-paragraph-link"><span class="named-paragraph">Actually compile</span><span class="named-paragraph-number">6.1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">made_fresh</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::up</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-cv.html#SP6">&#167;6</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP6_1_1" class="paragraph-anchor"></a><b>&#167;6.1.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Actually compile</span><span class="named-paragraph-number">6.1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Lvalues::is_lvalue</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><a href="2-cl.html#SP1" class="function-link"><span class="function-syntax">CompileLvalues::in_rvalue_context</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Rvalues::is_rvalue</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><a href="2-cr.html#SP1" class="function-link"><span class="function-syntax">CompileRvalues::compile</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">VH</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">vhmode_provided</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INTER_DATA_VHMODE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">VH</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">vhmode_wanted</span><span class="plain-syntax"> == </span><span class="identifier-syntax">INTER_VAL_VHMODE</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Holsters::unholster_to_code_val</span><span class="plain-syntax">(</span><span class="identifier-syntax">Emit::tree</span><span class="plain-syntax">(), </span><span class="identifier-syntax">VH</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Specifications::is_condition</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><a href="2-cc.html#SP1" class="function-link"><span class="function-syntax">CompileConditions::compile</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">VH</span><span class="plain-syntax">, </span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-cv.html#SP6_1">&#167;6.1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>"Casting" is converting a value of one kind to a value of another but which has
the same meaning, give or take. In a constant context, the main cast we can
perform is from literal <span class="extract"><span class="extract-syntax">K_number</span></span> values like <span class="extract"><span class="extract-syntax">31</span></span> to turn them into literal
<span class="extract"><span class="extract-syntax">K_real_number</span></span> values, a process called "promotion".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="function-syntax">CompileValues::cast_constant</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">CompileValues::cast_constant</span></span>:<br/><a href="2-cv.html#SP2">&#167;2</a>, <a href="2-cv.html#SP3">&#167;3</a>, <a href="2-cv.html#SP8">&#167;8</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NonlocalVariables::substitute_constants</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cv.html#SP9" class="function-link"><span class="function-syntax">CompileValues::note_that_kind_is_used</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">value</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LiteralReals::promote_number_if_necessary</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_found</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::to_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">K_understanding</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">Kinds::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_understanding</span><span class="plain-syntax">)) &amp;&amp; (</span><span class="identifier-syntax">Kinds::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_found</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_text</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Node::set_kind_of_value</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_understanding</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>In a value context we can additionally compile code to perform the conversion
at runtime, which extends the range of promotions we can make.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="function-syntax">CompileValues::cast_nonconstant</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">CompileValues::cast_nonconstant</span></span>:<br/><a href="2-cv.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">parse_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> *</span><span class="identifier-syntax">down</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Node::is</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">TABLE_ENTRY_NT</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">value</span><span class="plain-syntax"> = </span><a href="2-cv.html#SP7" class="function-link"><span class="function-syntax">CompileValues::cast_constant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K_found</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Specifications::to_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">value</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-cv.html#SP9" class="function-link"><span class="function-syntax">CompileValues::note_that_kind_is_used</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K_found</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">EmitCode::casting_call</span><span class="plain-syntax">(</span><span class="identifier-syntax">K_found</span><span class="plain-syntax">, </span><span class="identifier-syntax">K_wanted</span><span class="plain-syntax">, </span><span class="identifier-syntax">down</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>Certain kinds of value cannot be used on every virtual machine; for example,
the Z-machine does not support real numbers.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">VM_non_support_problem_issued</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::note_that_kind_is_used</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">CompileValues::note_that_kind_is_used</span></span>:<br/><a href="2-cv.html#SP6_1">&#167;6.1</a>, <a href="2-cv.html#SP7">&#167;7</a>, <a href="2-cv.html#SP8">&#167;8</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-cv.html#SP9" class="function-link"><span class="function-syntax">CompileValues::target_VM_supports_kind</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">VM_non_support_problem_issued</span><span class="plain-syntax"> == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">VM_non_support_problem_issued</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">StandardProblems::handmade_problem</span><span class="plain-syntax">(</span><span class="identifier-syntax">Task::syntax_tree</span><span class="plain-syntax">(),</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">_p_</span><span class="plain-syntax">(</span><span class="identifier-syntax">PM_KindRequiresGlulx</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_source</span><span class="plain-syntax">(1, </span><span class="identifier-syntax">current_sentence</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::quote_kind</span><span class="plain-syntax">(2, </span><span class="identifier-syntax">K</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_segment</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                </span><span class="string-syntax">"You wrote %1, but with the settings for this project as they are, "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"I'm unable to make use of %2. (Try changing to Glulx on the Settings "</span>
<span class="plain-syntax">                </span><span class="string-syntax">"panel; that should fix it.)"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">Problems::issue_problem_end</span><span class="plain-syntax">();</span>

<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">CompileValues::target_VM_supports_kind</span><span class="plain-syntax">(</span><span class="identifier-syntax">kind</span><span class="plain-syntax"> *</span><span class="identifier-syntax">K</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">target_vm</span><span class="plain-syntax"> *</span><span class="identifier-syntax">VM</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Task::vm</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">VM</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"target VM not set yet"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">Kinds::FloatingPoint::uses_floating_point</span><span class="plain-syntax">(</span><span class="identifier-syntax">K</span><span class="plain-syntax">)) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">TargetVMs::supports_floating_point</span><span class="plain-syntax">(</span><span class="identifier-syntax">VM</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="1-im.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-im.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresscurrent">cv</li><li class="progresssection"><a href="2-cr.html">cr</a></li><li class="progresssection"><a href="2-cl.html">cl</a></li><li class="progresssection"><a href="2-cc.html">cc</a></li><li class="progresssection"><a href="2-map.html">map</a></li><li class="progresssection"><a href="2-mgap.html">mgap</a></li><li class="progresschapter"><a href="3-sf.html">3</a></li><li class="progresschapter"><a href="4-cs.html">4</a></li><li class="progresschapter"><a href="5-cbal.html">5</a></li><li class="progressnext"><a href="2-cr.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

